<template>
	<view>
		<navbar 
			title-text=" " 
			:isHeight="false" 
			:isWhite="true" 
			background="none" 
			@navBarAttached="onNavBarAttached" 
		/>
		<view style="position: relative;">
			<image
				:src="hospital.avatar_url"
				mode="aspectFill"
				class="avatar_img1"
			></image>
			<view :style="'position:absolute;top:' + navBarHeight + 'rpx;padding-top:65rpx;overflow:hidden;width:100%;'">
				<view class="hospital-hd">
					<view 
						class="weui-cell weui-cell_access" 
						hover-class="weui-cell_active" 
						@tap="showShareModal">
						<view class="weui-cell__hd">
							<image
								:src="hospital.avatar_url"
								mode="aspectFill"
								class="avatar_img2"
							></image>
						</view>
						<view class="weui-cell__bd" style="padding-left: 170rpx">
							<view style="position: absolute; top: -65rpx">
								<text class="hospital_txt">{{ hospital.name }}</text>
							</view>
							<view>
								<text class="hosp-rank">{{ hospital.rank }}</text>
								<text class="hosp-label">{{ hospital.label }}</text>
							</view>
						</view>
						<view class="weui-cell__ft weui-cell__ft_in-access"><text class="f4">转发</text></view>
					</view>
					<view class="weui-cell weui-cell_access" hover-class="weui-cell_active" @tap="toMap">
						<view class="weui-cell__hd">
							<image
								src="/static/resource/images/ic_address.png"
								mode="aspectFill"
								class="address_img"
							></image>
						</view>
						<view class="weui-cell__bd">
							<view>
								<text style="font-size: 24rpx">
								{{ hospital.city }}{{ hospital.district }}{{ hospital.address }}
								</text>
							</view>
						</view>
						<view class="weui-cell__ft weui-cell__ft_in-access"><text class="f4">导航</text></view>
					</view>
				</view>
				<view class="hospital-bd">
					<view class="weui-cells serv-list">
						<view class="weui-cell serv-item">
							<view class="weui-cell__bd">
								<view style="padding-top: 10rpx"><text class="serv-name">在线预约您需要的服务</text></view>
							</view>
							<view class="weui-cell__ft"></view>
						</view>
						<view 
							class="weui-cell serv-item" 
							@tap="toService" 
							:data-svid="item.id" v-for="(item, index) in services" 
							:key="index">
							<block v-if="item.use_switch == 1">
								<view class="weui-cell__hd">
									<image 
										class="serv-logo" 
										:src="item.logo_image_url || '../../resource/images/avatar.jpg'" 
										mode="aspectFill" 
									/>
								</view>
								
								<view class="weui-cell__bd">
									<view>
										<text class="serv-name">{{ item.name }}</text>
									</view>
									<view class="serv-line serv-intro">{{ item.intro }}</view>
									<view class="serv-line">
										<text class="serv-price">{{ item.price }}</text>
										<text class="serv-unit">元/次</text>
									</view>
								</view>
								
								<view class="weui-cell__ft">
									<button class="btn1m">预约</button>
								</view>
							</block>
						</view>
					</view>
				</view>
			</view>
		</view>
		<share :shareModal.sync="clone_shareModal"></share>
	</view>
</template>

<script>
	// import plugin from 'routePlan'
	const app = getApp()
	export default {
		data() {
			return {
				navBarHeight:'',
				hospital:{},
				//转发弹框
				clone_shareModal: false,
				//所需要的服务
				services:[]
			}
		},
		async onLoad({hid}){
			const {data} = await app.globalData.utils.request({
				url:'/Hospital/index',
				data:{
					hid
				}
			})
			this.hospital = data.hospital
			this.services = data.services
		},
		methods: {
			//获取navBar的高度
			onNavBarAttached({navBarHeight}){
				this.navBarHeight = navBarHeight
			},
			//转发
			showShareModal(){
				this.clone_shareModal = true
				console.log(this.clone_shareModal)
			},
			//导航
			toMap(){
				let plugin = requirePlugin('routePlan');
				const point = this.bMapTransQQMap(this.hospital.lng,this.hospital.lat)
				const endPoint = JSON.stringify({
					name:this.hospital.name,
					latitude: point.lat,
					longitude:point.lng
				})
				uni.navigateTo({
					url:`plugin://routePlan/index?key=KUJBZ-5G6LN-HDJFC-SM7RI-BBJHT-5HBFS&referer=''&endPoint=${endPoint}&navigation=1`
				})
			},
			//地图位置坐标系的计算
			 bMapTransQQMap(lng,lat){
				let x_pi = (3.141592653589793 * 3000) / 180
				let x  = lng - 0.0065
				let y = lat - 0.006
				let z = Math.sqrt ( x * x + y * y) - 0.00002 * Math.sin (y * x_pi)
				let theta = Math.atan2(y,x) - 0.000003 * Math.cos (x * x_pi)
				let lngs = z * Math.cos(theta)
				let lats = z * Math.sin(theta)
				return {
					lng:lngs,
					lat:lats
				}
			},
			//服务列表跳转到下单页
			toService(e){
				uni.navigateTo({
					url:`../service/index?hid=${this.hospital.id}&svid=${e.currentTarget.dataset.svid}`
				})
			}
		}
	}
</script>

<style>
@import './index.css'
</style>
